package com.kingdee.eas.jky.crm.app;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.crm.BusinessManageAssistEntryFactory;
import com.kingdee.eas.custom.crm.BusinessManageAssistEntryInfo;
import com.kingdee.eas.custom.crm.BusinessManageFactory;
import com.kingdee.eas.custom.crm.BusinessManageInfo;
import com.kingdee.eas.custom.crm.IBusinessManageAssistEntry;
import com.kingdee.eas.jky.crm.AdmPersonEntryCollection;
import com.kingdee.eas.jky.crm.AdmPersonEntryInfo;
import com.kingdee.eas.jky.crm.AdmPersonInfo;

public class AdmPersonControllerBean extends AbstractAdmPersonControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.jky.crm.app.AdmPersonControllerBean");
    protected void _audit(Context ctx, IObjectPK pk)throws BOSException, EASBizException
    {
         super._audit(ctx, pk);
         AdmPersonInfo info = getAdmPersonInfo(ctx, pk);
			if (info.getSourceBillId() != null) {
				String souID = info.getSourceBillId();
				BusinessManageInfo buInfo = BusinessManageFactory.getLocalInstance(ctx).getBusinessManageInfo(new ObjectUuidPK(souID));
				buInfo.setPerson(info.getPerson());
				buInfo.setDeparment(info.getDeparment());
				buInfo.setIsKuaArea(info.isIsKuaArea());
				BusinessManageFactory.getLocalInstance(ctx).update(new ObjectUuidPK(buInfo.getId().toString()), buInfo);
				AdmPersonEntryCollection AdmPersonEntryColl =info.getEntry();
				if(AdmPersonEntryColl.size()>0){
					IBusinessManageAssistEntry bussPersonEntry =BusinessManageAssistEntryFactory.getLocalInstance(ctx);
	        		 for(int i=0; i<AdmPersonEntryColl.size(); i++){
	        			 AdmPersonEntryInfo AadmEnInfo = AdmPersonEntryColl.get(i);
	        			   if(AadmEnInfo.getSourceID()!=null){
	        				   BusinessManageAssistEntryInfo bussPersonInfo =bussPersonEntry.getBusinessManageAssistEntryInfo(new ObjectUuidPK(AadmEnInfo.getSourceID()));
	        				   bussPersonInfo.setPNsme(AadmEnInfo.getPsNsme());
	        				   bussPersonInfo.setPDep(AadmEnInfo.getPDep());
	        				   bussPersonInfo.setLotRate(AadmEnInfo.getLotRate());
	        				   bussPersonInfo.setTcfpbl(AadmEnInfo.getTcfpbl());
	        				   bussPersonInfo.setIsMain(AadmEnInfo.isIsMain());
	        				   bussPersonEntry.update(new ObjectUuidPK(bussPersonInfo.getId().toString()), bussPersonInfo);
	        			   }else{
	        				   BusinessManageAssistEntryInfo  bussPersonInfo =new BusinessManageAssistEntryInfo();
	        				   bussPersonInfo.setParent(buInfo);
	        				   bussPersonInfo.setPNsme(AadmEnInfo.getPsNsme());
	        				   bussPersonInfo.setPDep(AadmEnInfo.getPDep());
	        				   bussPersonInfo.setLotRate(AadmEnInfo.getLotRate());
	        				   bussPersonInfo.setTcfpbl(AadmEnInfo.getTcfpbl());
	        				   bussPersonInfo.setIsMain(AadmEnInfo.isIsMain());
	        				   bussPersonEntry.save(bussPersonInfo);
	        			   }
	        		 }
				}
			}
    }
    protected void _unAudit(Context ctx, IObjectPK pk)throws BOSException, EASBizException
    {
         super._unAudit(ctx, pk);
    }
    protected void _unAudit(Context ctx, IObjectPK[] pks)throws BOSException, EASBizException
    {
         super._unAudit(ctx, pks);
    }
    protected void _backEdit(Context ctx, IObjectValue model)throws BOSException
    {
    }
}